//**********************************************************************************************************************
// Ham node_name_onclick()
// Y nghia: 
// - Neu o che do cho phep THEM/SUA/XOA thi hien thi man hinh cap nhat 1 doi tuong
// - Neu o che do KHONG cho phep THEM/SUA/XOA thi tra lai 1 chuoi gom ID,CODE,NAME cua doi tuong
// Tham so:
// - node: doi tuong ma NSD nhan CHUOT
//**********************************************************************************************************************
//**********************************************************************************************************************
// Ham node_name_onclick()
// Y nghia: 
// - Neu o che do cho phep THEM/SUA/XOA thi hien thi man hinh cap nhat 1 doi tuong
// - Neu o che do KHONG cho phep THEM/SUA/XOA thi tra lai 1 chuoi gom ID,CODE,NAME cua doi tuong
// Tham so:
// - node: doi tuong ma NSD nhan CHUOT
//**********************************************************************************************************************
var xmlHttp, contentID;
var contentIDBlock = false;

function node_name_onclick_vunh(node,select_parent){	
	if (node.type.valueOf() == 1) {
		var user_id = node.id;
		var parent_id = node.getAttribute("parent_id");
		var url = "index.php?fuseaction=GET_LIST_BY_USER_ID&id=" + user_id + "&id_unit=" + parent_id + "&modal_dialog_mode=1";			
		startRequest("GET", url, handleContainer);
	} else {
		if (node.type.valueOf() == 0) {
			var unit_id = node.id;
			var url = "index.php?fuseaction=GET_LIST_BY_UNIT_ID&id_unit=" + unit_id + "&modal_dialog_mode=1";			
			//alert(url);
			startRequest("GET", url, handleContainer);
		}
	}
}

function handleContainer() {
	if(xmlHttp.readyState==1) {
		//document.getElementById("content").innerHTML = "";
		document.getElementById("load").style.display = "block";
	}
	if(xmlHttp.readyState==4) {
		document.getElementById("load").style.display = "none";		
		eval('document.getElementById("' + "content" + '").innerHTML = xmlHttp.responseText');
		//eval('document.getElementById("' + contentID + '").innerHTML = xmlHttp.responseText');		
	}
}

function createXMLHttpRequest() {
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
}

function startRequest(method, url, handle) {
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handle;
	xmlHttp.open(method, url, handle);
	xmlHttp.send(null);
}

function handle_page_onchange() {
	if(xmlHttp.readyState==1) {
		//document.getElementById("content").innerHTML = "";		
		document.getElementById("load").style.display = "block";		
	}
	if(xmlHttp.readyState==4) {		
		document.getElementById("load").style.display = "none";		
		eval('document.getElementById("' + contentID + '").innerHTML = xmlHttp.responseText');
		//eval('document.getElementById("' + contentID + '").innerHTML = xmlHttp.responseText');				
	}
}

//Ham nay thuc thi khi NSD nhan vao mot trang tren danh sach
function page_onchange_vunh(sel_obj,p_fuseaction,form_id){
	var page_value = sel_obj.value;
	var fuseaction_value = p_fuseaction;
	var user_id = form_id.id.value;
	form_id.hdn_page.value = page_value;
	form_id.fuseaction.value = fuseaction_value;
	var url = "index.php?fuseaction=" + p_fuseaction + "&id=" + user_id + "&modal_dialog_mode=0&hdn_page=" + page_value;	
	contentID = "div_id_" + user_id;		
	startRequest("GET", url, handle_page_onchange);
}
//Ham thay thuc thi khi NSD muon thay doi so dong quy dinh tren mot trang
function page_record_number_onchange_vunh(sel_obj,p_fuseaction,form_id){
	var record_number_per_page_value = sel_obj.value;
	var fuseaction_value = p_fuseaction;
	var user_id = form_id.id.value;
	form_id.hdn_page.value = 1;
	form_id.hdn_record_number_page.value = record_number_per_page_value;
	form_id.fuseaction.value = fuseaction_value;
	var url = "index.php?fuseaction=" + p_fuseaction + "&id=" + user_id + "&modal_dialog_mode=0" + "&hdn_record_number_page=" + record_number_per_page_value;	
	contentID = "div_id_" + user_id;	
	startRequest("GET", url, handle_page_onchange);
}

function show_hide_content(content_id) {
	var content_obj = document.getElementById(content_id);
	if (content_obj.style.display == "none") {
			document.getElementById(content_id).style.display = "block";
	} else {
			document.getElementById(content_id).style.display = "none";
	}
}